"use strict";
var 颜色 = (function () {
    function 颜色(r, g, b) {
        this.r = 颜色.验证(r);
        this.g = 颜色.验证(g);
        this.b = 颜色.验证(b);
    }
    Object.defineProperty(颜色.prototype, "取值", {
        get: function () {
            return 颜色.转十六进制(this.r, this.g, this.b);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(颜色.prototype, "取rgb", {
        get: function () {
            return 'rgb(' + this.r.toString() + ',' + this.g.toString() + ',' + this.b.toString() + ')';
        },
        enumerable: true,
        configurable: true
    });
    颜色.prototype.加 = function (颜色2) {
        this.r = this.r + 颜色2.r;
        this.g = this.g + 颜色2.g;
        this.b = this.b + 颜色2.b;
        return this.取值;
    };
    颜色.prototype.减 = function (颜色2) {
        this.r = this.r - 颜色2.r;
        this.g = this.g - 颜色2.g;
        this.b = this.b - 颜色2.b;
        return this.取值;
    };
    颜色.prototype.乘 = function (乘数) {
        this.r = this.r == 0 ? 1 * 乘数 : this.r * 乘数;
        this.g = this.g == 0 ? 1 * 乘数 : this.g * 乘数;
        this.b = this.b == 0 ? 1 * 乘数 : this.b * 乘数;
        return this.取值;
    };
    颜色.prototype.除 = function (除数) {
        var 除数2 = 除数 == 0 ? 1 : 除数;
        this.r = this.r / 除数2;
        this.g = this.g / 除数2;
        this.b = this.b / 除数2;
        return this.取值;
    };
    颜色.验证 = function (值) {
        值 = 值 > 255 ? 255 : 值 < 0 ? 0 : Math.round(值);
        return 值;
    };
    颜色.转十六进制 = function (r, g, b) {
        var rr = 颜色.验证(r);
        var gg = 颜色.验证(g);
        var bb = 颜色.验证(b);
        var rrr = rr.toString(16);
        var ggg = gg.toString(16);
        var bbb = bb.toString(16);
        return '#' + (rrr.length == 1 ? '0' + rrr : rrr) + (ggg.length == 1 ? '0' + ggg : ggg) + (bbb.length == 1 ? '0' + bbb : bbb);
    };
    颜色.转十进制 = function (颜色) {
        if ((颜色.length != 4) && (颜色.length != 7)) {
            throw '输入有错误';
        }
        var 转换值 = 颜色.slice(1);
        var rr, gg, bb;
        if (转换值.length == 3) {
            rr = 转换值.slice(0, 1) + 转换值.slice(0, 1);
            gg = 转换值.slice(1, 2) + 转换值.slice(1, 2);
            bb = 转换值.slice(2, 3) + 转换值.slice(2, 3);
        }
        else {
            rr = 转换值.slice(0, 2);
            gg = 转换值.slice(2, 4);
            bb = 转换值.slice(4, 6);
        }
        var r = parseInt(parseInt(rr, 16).toString(10));
        var g = parseInt(parseInt(gg, 16).toString(10));
        var b = parseInt(parseInt(bb, 16).toString(10));
        return { r: r, g: g, b: b };
    };
    颜色.rgba = function (r, g, b, a) {
        r = 颜色.验证(r);
        g = 颜色.验证(g);
        b = 颜色.验证(b);
        a = a > 1 ? 1 : a < 0 ? 0 : a;
        return 'rgba(' + r.toString() + ',' + g.toString() + ',' + b.toString() + ',' + a.toString() + ')';
    };
    颜色.rgb = function (r, g, b) {
        return new 颜色(r, g, b);
    };
    颜色.加 = function (颜色1, 颜色2) {
        if (颜色1 == '' || typeof 颜色1 == 'undefined') {
            return 颜色2;
        }
        var r = 颜色1.r + 颜色2.r;
        var g = 颜色1.g + 颜色2.g;
        var b = 颜色1.b + 颜色2.b;
        return new 颜色(r, g, b);
    };
    颜色.减 = function (颜色1, 颜色2) {
        if (颜色1 == '' || typeof 颜色1 == 'undefined') {
            return 颜色2;
        }
        var r = 颜色1.r - 颜色2.r;
        var g = 颜色1.g - 颜色2.g;
        var b = 颜色1.b - 颜色2.b;
        return new 颜色(r, g, b);
    };
    颜色.乘 = function (颜色1, 乘数) {
        if (颜色1 == '') {
            return 颜色1;
        }
        var r = 颜色1.r == 0 ? 乘数 : 颜色1.r * 乘数;
        var g = 颜色1.g == 0 ? 乘数 : 颜色1.g * 乘数;
        var b = 颜色1.b == 0 ? 乘数 : 颜色1.b * 乘数;
        return new 颜色(r, g, b);
    };
    颜色.除 = function (颜色1, 除数) {
        if (颜色1 == '') {
            return 颜色1;
        }
        var 除数2 = 除数 == 0 ? 1 : 除数;
        var r = 颜色1.r / 除数2;
        var g = 颜色1.g / 除数2;
        var b = 颜色1.b / 除数2;
        return new 颜色(r, g, b);
    };
    return 颜色;
}());
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = 颜色;
